<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:69:"E:\WWW\newadmin.cc\public/../application/admin\view\backup\index.html";i:1679565730;s:58:"E:\WWW\newadmin.cc\application\admin\view\common\meta.html";i:1670904727;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/admin/layuiadmin/style/admin.css" media="all">
  <script src="/static/echarts/echarts.js"></script>
  <script src="/static/admin/js/jquery-1.8.3.min.js"></script>
  <script src="/static/mods/notify_stand.js"></script>
</head>
<script>
  function clickimg(obj,img_tis){
    var img=$('#'+img_tis).val();
    console.log(img)
    var imgs=img.split(',');
    var arr=new Array();
    for(var i=0;i<imgs.length;i++){
      if(imgs[i]){
        if(i!=$(obj).index()){
        arr.push(imgs[i]);
      }
      }
    }
    $(obj).parent().remove();
    console.log(arr);
    $('#'+img_tis).val(arr.join(','));
    notify.success("操作成功", 'topRight');
}
function previewImg(obj) {
    var img = new Image(); 
    img.src = obj.src;
    //var height = img.height + 50; // 原图片大小
    //var width = img.width; //原图片大小
    var imgHtml = "<img src='" + obj.src + "' width='500px' height='500px'/>"; 
    //弹出层
    layer.open({ 
      type: 1, 
      shade: 0.8,
      offset: 'auto',
      area: [501 + 'px',551+'px'], // area: [width + 'px',height+'px'] //原图显示
      shadeClose:true,
      scrollbar: false,
      title: "图片预览", //不显示标题 
      content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响 
      cancel: function () { 
        //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 }); 
      } 
    }); 
  }
</script>
<style>
  .previewImg{
    width: 100px;
    cursor:pointer;
  }
  .layui-btn_text{
    color: #009688;
    cursor:pointer;
  }
  .layui-btn_text-danger{
    color: #FF5722;
  }
  .layui-btn_text-danger:hover {
    color: #ff3c00;
}
.imgs_posi{
    position: relative;
    width: 200px;
    float: left;
  }

  .imgs_posi img{
    width: 100%;
  }
  .img_ab{
    position: absolute;
    right: 10px;
    top:5px;
    background-color: aliceblue;
    color: #333;
    font-size: 16px;
    height: 20px;
    line-height: 20px;
    width: 20px;
    text-align: center;
    border-radius: 20px;
    cursor: pointer;
  }
  .layui-elem-quote{
    overflow: hidden;
  }
</style>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card" style="padding-bottom: 100px;">
  <div style="width: 96%;margin: 0 auto;">
 <div class="layui-form" style="padding-top: 30px;">
   <div class="layui-form-item">
     <div class="layui-inline">
       <label class="layui-form-label">时间范围</label>
	         <div class="layui-input-inline">
	           <input type="text" class="layui-input" id="test10" placeholder="年-月-日 - 年-月-日" autocomplete="off">
	         </div>
       <!-- <div class="layui-input-inline">
         <input type="text" id="name" name="name" placeholder="搜索关键词" class="layui-input">
       </div> -->
       <button class="layui-btn layui-btn-sm" id="sub">提交</button>
     </div>
   </div>
 </div>
   <!-- <button class="layui-btn layui-btn-sm" onclick="add_date(this)" >
    <i class="layui-icon">&#xe608;</i> 添加栏目
  </button> -->
  <table class="layui-hide" id="demo" lay-filter="test"></table>
</div>
</div>
</div>
</div>
</div>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-sm " target="_blank" href="/{{d.backup_name}}{{d.name}}-1.sql" >下载</a>
  <a class="layui-btn layui-btn-sm " lay-event="save">恢复</a>
  <a class="layui-btn layui-btn-danger layui-btn-sm " lay-event="del">删除</a>
</script>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add">备份数据库</button>
    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delall">批量删除</button>
  </div>
</script>
  <script src="/static/layui/layui.js"></script>  
  <script type="text/html" id="switchTpl">
  	 <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-filter="status" lay-text="启用|禁用"  {{ d.status == 1 ? 'checked' : '' }}>

  </script>

<script>

 
layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function(){
  var laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,carousel = layui.carousel //轮播
  ,upload = layui.upload //上传
  ,element = layui.element //元素操作
  ,$ = layui.$
	,form = layui.form;
 //日期时间范围
  laydate.render({
    elem: '#test10'
    ,type: 'datetime'
	,range: ','
	,format: 'yyyy-M-d'
  });
 
  
  //执行一个 table 实例
  table.render({
    elem: '#demo'
    ,url: '<?php echo url("backup/lists"); ?>' //数据接口
    ,page: true //开启分页
	, id: 'testReload'
  ,toolbar: '#toolbarDemo'
    ,cols: [[ //表头
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'adminname', title: '备份人',}
      ,{field: 'backup_name', title: '路径',}
      ,{field: 'backup_time', title: '备份时间',  sort: true,width: 200, totalRow: true}
      ,{fixed: 'right',title: '操作', width: 200, align:'center', toolbar: '#barDemo'}
    ]]
  });

 //头工具栏事件
 table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'add':
     
      layer.confirm('确定备份吗', function(index){
        layer.closeAll();
        layer.load();
          $.post("<?php echo url('backup/add'); ?>",function (data) {
        layer.closeAll();
            if(data.code=='200'){
              notify.success(data.msg,'topRight');
                // layer.msg('备份成功',{time: 1000},function(){
                table.reload('testReload');
              // });
            }else{
              notify.error(data.msg,'topRight');
              // layer.msg(data.msg);
            }
        },'json')
        });
      break;
      case 'delall':
        var data = checkStatus.data;
        var id=Array();
        for(var i=0;i<data.length;i++){
          id.push(data[i].id);
        }
        console.log(id);
        layer.confirm('确定批量删除吗', function(index){
          $.post("<?php echo url('backup/delall'); ?>",{id:id},function (data) {
            layer.closeAll();
            if(data.code=='200'){
              notify.success('操作成功','topRight');
                // layer.msg('操作成功',{time: 1000},function(){
                table.reload('testReload');
              // });
            }else{
              notify.error(res.msg,'topRight');
            }
        },'json')
          //向服务端发送删除指令
        });
          
        // layer.alert(JSON.stringify(ids));
      break;
      
    };
  });
  //监听行工具事件
    table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
      var data = obj.data //获得当前行数据
      ,layEvent = obj.event; //获得 lay-event 对应的值
      if(layEvent === 'detail'){
        // layer.msg('查看操作');
        // notify.error(res.msg,'topRight');
      } else if(layEvent === 'del'){
        layer.confirm('真的删除么', function(index){
          $.post("<?php echo url('backup/del_list'); ?>",{id:data.id},function(res){
            layer.closeAll();
          	if(res.code=='200'){
              notify.success('操作成功','topRight');
          		obj.del(); //删除对应行（tr）的DOM结构
          		// layer.closeAll();
          		}else{
                notify.error(res.msg,'topRight');
          		// layer.msg(res.msg, {time: 2000});
          	}
          },'json');
          //向服务端发送删除指令
        });
      } else if(layEvent === 'save'){
        layer.confirm('确定恢复数据库吗', function(index){
          var index = layer.load();
          $.post("<?php echo url('backup/save'); ?>",{id:data.id},function (data) {
            layer.closeAll();
            if(data.code=='200'){
              notify.success('操作成功','topRight');
                // layer.msg('恢复数据库成功',{time: 1000},function(){
                table.reload('testReload');
              // });
            }else{
              notify.error(res.msg,'topRight');
              // layer.close(index);
              // layer.msg(data.msg);
            }
        },'json')
          //向服务端发送删除指令
        });
      }
    });
	//搜索
  $('#sub').click(function () {
    var name=$('#name').val();
	var time=$('#test10').val();
    table.reload('testReload', {
    url: '<?php echo url("backup/lists"); ?>'
    // ,methods:"post"
    ,where: {
     name : name,
	  time:time,
    }
    ,page: {
     curr: 1
    }
    });
   })

 //监听性别操作
   form.on('switch(status)', function(obj){
     // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
	 var sta=obj.elem.checked?1:2;
	 $.post("<?php echo url('backup/status'); ?>",{id:this.value,sta:sta},function (data) {
	       if(data.code=='200'){
          notify.success('操作成功','topRight');
			  //  layer.msg('修改成功');
		   }else{
        notify.error('操作成功','topRight');
			  //  layer.msg('修改失败');
		   }
	 },'json')
   });
 



});

function add_date(thi){
	layer.open({
      type: 2,
      title: '添加栏目',
      shadeClose: true,
      shade: 0.6,
      maxmin: true, //开启最大化最小化按钮
      area: ['80%', '90%'],
      content: "<?php echo url('backup/save'); ?>"
    });
}



</script>
</body>
</html>        
